@{
    ViewBag.Title = "分类管理";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var keyValue = SF.utility.request('keyValue');
    var parentId = SF.utility.request('ParentId');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {

        //获取表单
        if (!!keyValue) {
            SF.utility.setForm({
                url: "/Api/DataItem/" + keyValue,
                success: function (data) {
                    SF.utility.setWebControls('form1', data);
                    onBeforLoadForm(data.ParentId, data.ParentPath);
                }
            });
        } else {
            onBeforLoadForm(parentId, '');
        }
    }

    function onBeforLoadForm(parentId, parentPath) {
        $("#hfInitialItemParentIds").val(parentPath);
        $("#ParentId").val(parentId);
        //上级
        SF.controls.itemPicker.initialize({
            controlId: 'SelectParentId',
            restUrl: '/Api/DataItem/GetChildren/',
            allowMultiSelect: false,
            defaultText: '',
            expandedIds: [parentId],
            success: function (data) {
            },
            selected: function (id) {
            },

        });

    }
    //保存表单
    function AcceptClick(type) {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = SF.utility.getWebControls('form1', keyValue);
        if (postData["ParentId"] == "") {
            postData["ParentId"] = 0;
        }
        var url = "/Api/DataItem/";
        if (type == "PUT")
            url = url + keyValue;
        else if (type == "POST")
            url = url;
        SF.utility.saveForm({
            type: type,
            url: url,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                if (top.Form == undefined) {
                    SF.utility.currentIframe().$("#gridTable").resetSelection();
                    SF.utility.currentIframe().$("#gridTable").trigger("reloadGrid");
                } else {
                    top.Form.$("#gridTable").resetSelection();
                    top.Form.$("#gridTable").trigger("reloadGrid");
                }
            }
        })
    }


</script>
<div class="block-content">
    <div class="panel panel_no_boder panel-block">
        <div class="panel-body form-horizontal">
            <div class="alert alert-danger" style="display:none;">
            </div>
            <fieldset>
                <div class="form-group page-picker  required">
                    <label class="col-md-3 control-label" for="ppPage">上级</label>
                    <div class="col-md-9 control-wrapper">
                        <div id="SelectParentId" class="picker picker-select rollover-container " type="selectTree">
                            <input class="js-item-id-value" type="hidden" name="ParentId" id="ParentId" />
                            <input class="js-initial-item-parent-ids-value" type="hidden" id="hfInitialItemParentIds" />
                            <input class="js-item-name-value" type="hidden" name="hfItemName" id="hfItemName" />
                            <input class="js-item-rest-url-extra-params-value" type="hidden" id="hfItemRestUrlExtraParams" />
                            <a class='picker-label' href='#'>
                                <i class='fa fa-file icon-fw'></i>
                                <span class='selected-names'></span>
                                <b class='fa fa-caret-down pull-right'></b>
                            </a>
                            <a class="picker-select-none" style="display:none;"><i class='fa fa-times'></i></a>
                            <div class="picker-menu dropdown-menu">
                                <div class='scroll-container scroll-container-vertical scroll-container-picker'>
                                    <div class='scrollbar'>
                                        <div class='track'>
                                            <div class='thumb'>
                                                <div class='end'></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class='viewport'>
                                        <div class='overview'>
                                            <div class='treeview treeview-items'></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="picker-actions">
                                    <a id="btnSelect" class="btn btn-xs btn-primary picker-btn">选择</a>
                                    <a class='btn btn-xs btn-link picker-cancel' id='btnCancel_ppPage'>取消</a>
                                    <a id="btnSelectCurrentPage" title="选择当前页" class="btn btn-xs btn-link pull-right"><i class='fa fa-file-o'></i></a>

                                </div>
                            </div>
                        </div>
                    </div>
                    <span id="rfv" class="validation-error help-inline" style="display:none;">Page is Required.</span>
                </div>
                <div class="form-group data-text-box  required">
                    <label class="col-md-3 control-label" for="ItemName">名称</label>
                    <div class="col-md-9 control-wrapper">
                        <input id="ItemName" name="ItemName" type="text" onblur="SF.utility.existField(this.id, '/Api/DataItem/ExistItemName')" class="form-control" placeholder="请输入名称" isvalid="yes" checkexpession="NotNull" />
                    </div>
                </div>
                <div class="form-group data-text-box  required">
                    <label class="col-md-3 control-label" for="ItemCode">编号</label>
                    <div class="col-md-9 control-wrapper">
                        <input id="ItemCode" name="ItemCode" type="text" onblur="SF.utility.existField(this.id, '/Api/DataItem/ExistItemCode')" class="form-control" placeholder="请输入编号" isvalid="yes" checkexpession="NotNull" />
                    </div>
                </div>
                <div class="form-group data-text-box  required">
                    <label class="col-md-3 control-label" for="SortIndex">排序</label>
                    <div class="col-md-9 control-wrapper">
                        <input id="SortIndex" name="SortIndex" type="text" class="form-control" isvalid="yes" checkexpession="Num" />
                    </div>
                </div>
                <div class="form-group data-text-box  required">
                    <label class="col-md-3 control-label"></label>
                    <div class="col-md-9 control-wrapper">
                        <div class="checkbox">
                            <label>
                                <input id="IsTree" type="checkbox" />
                                树型
                            </label>
                            <label>
                                <input id="EnabledMark" type="checkbox" checked="checked" />
                                有效
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-group data-text-box ">
                    <label class="col-md-3 control-label" for="Description"></label>
                    <div class="col-md-9 control-wrapper">
                        <textarea id="Description" class="form-control" style="height: 70px;"></textarea>
                    </div>

                </div>
            </fieldset>
        </div>
    </div>
</div>


